﻿Imports System.Data.OleDb
Imports System.Drawing

Public Class AddProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim PictGUID As New System.Guid
        PictGUID = Guid.NewGuid()
        Dim imgfilename As String = PictGUID.ToString + "Large.jpg"
        Dim smallimgname As String = PictGUID.ToString + "small.jpg"


        Dim imgThumb As Image = Nothing
      

        Dim imgpath As String

        If fileuploadImage.HasFile Then
            imgpath = Request.MapPath("Images")
            fileuploadImage.SaveAs(imgpath & "\" & imgfilename)
            Dim image1 As Bitmap = _
          CType(Image.FromFile(imgpath & "\" & imgfilename, True), Bitmap)
            Dim thheight = image1.Height \ 15
            Dim thwidth = image1.Width \ 15
            If Not image1 Is Nothing Then
                imgThumb = image1.GetThumbnailImage(100, 100, Nothing, New IntPtr())
            End If
            imgThumb.Save(imgpath & "\" & smallimgname)
        End If
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("fishconn").ConnectionString)
        Dim SqlString As String = "Insert into tblProfile(FirstName, LastName, Address, State, Country, EmailAddress, Gender, DateofBirth, " & _
                                  "PhoneNumber, Description, ProfilePicture, ProfilePicturesmall, Interest, DisplayMessage) " & _
                                  " Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12,@f13,@f14)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtFname.Text)
        cmd.Parameters.AddWithValue("@f2", txtLname.Text)
        cmd.Parameters.AddWithValue("@f3", txtaddress.Text)
        cmd.Parameters.AddWithValue("@f4", txtState.Text)
        cmd.Parameters.AddWithValue("@f5", txtcountry.Text)
        cmd.Parameters.AddWithValue("@f6", txtemail.Text)
        cmd.Parameters.AddWithValue("@f7", cbxSex.Text)
        cmd.Parameters.AddWithValue("@f1", txtDOB.Text)
        cmd.Parameters.AddWithValue("@f2", txtphone.Text)
        cmd.Parameters.AddWithValue("@f3", txtDescription.Text)
        cmd.Parameters.AddWithValue("@f4", "images\" & imgfilename)
        cmd.Parameters.AddWithValue("@f5", "images\" & smallimgname)
        cmd.Parameters.AddWithValue("@f6", TxtInterest.Text)
        cmd.Parameters.AddWithValue("@f7", txtdisplaymessage.Text)
        oleDbConn.Open()
        If cmd.ExecuteNonQuery() = 1 Then
            Response.Redirect("list.aspx")
        End If
    End Sub
End Class